package _32define;

import java.util.*;
import java.util.stream.Collectors;

public class HomeWork2 {
    public static void main(String[] args) {
        List<User> list= Arrays.asList(
                new User("zs",18),
                new User("ls",19),
                new User("zs",18),
                new User("ll",21));
        List<User> newList=list.stream().distinct().collect(Collectors.toList());
        System.out.println(list);
        System.out.println(newList);
    }


}
class User{
    private String name;
    private int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean equals(Object o){
        if (this==o){
            return true;
        }
        if (o==null||getClass()!=o.getClass()){
            return false;
        }
        User user=(User) o;
        return age== user.age&& Objects.equals(name,user.name);
    }
    public int hashCode(){
        return Objects.hash(name,age);
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
